package org.egrit;

import java.awt.Point;

import com.google.common.base.Predicate;

/**
 * An iterator that returns cells within the given bounds that having
 * values that satisfy a specified condition.
 *
 * @author michael
 */
public class ConditionalValueGridIterator extends AbstractConditionalGridBoundsIterator {

    private final IGrid valueGrid;
    private final Predicate<Number> cond;

    public ConditionalValueGridIterator(IGridBounds bounds, IGrid valueGrid, Predicate<Number> cond) {
        super(bounds);
        this.valueGrid = valueGrid;
        this.cond = cond;
    }

    @Override
    protected boolean testInclusion(Point candidatePos) {
        return cond.apply(valueGrid.getGridValue(candidatePos));
    }

}
